home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 13 / Game / Game.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  5.0 KB  |  132 lines

  1. //-----------------------------------------------------------------------------
  2. // The derived game state where all the game's processing happens.
  3. //
  4. // Programming a Multiplayer First Person Shooter in DirectX
  5. // Copyright (c) 2004 Vaughan Young
  6. //-----------------------------------------------------------------------------
  7. #ifndef GAME_H
  8. #define GAME_H
  9.  
  10. //-----------------------------------------------------------------------------
  11. // State ID Define
  12. //-----------------------------------------------------------------------------
  13. #define STATE_GAME 1
  14.  
  15. //-----------------------------------------------------------------------------
  16. // Enumerated Spawn Object Types
  17. //-----------------------------------------------------------------------------
  18. enum{ WEAPON_SPAWN_OBJECT };
  19.  
  20. //-----------------------------------------------------------------------------
  21. // Custom Network Message Defines
  22. //-----------------------------------------------------------------------------
  23. #define MSGID_PLAYER_HEALTH          0x12005
  24. #define MSGID_PLAYER_MOVE_UPDATE     0x12006
  25. #define MSGID_PLAYER_LOOK_UPDATE     0x12007
  26. #define MSGID_PLAYER_SCORE           0x12008
  27. #define MSGID_PLAYER_WEAPON_CHANGE   0x12009
  28. #define MSGID_PLAYER_WEAPON_CHANGING 0x12010
  29. #define MSGID_SPAWN_POINT_REQUEST    0x12011
  30. #define MSGID_SPAWN_POINT            0x12012
  31. #define MSGID_SPAWN_PLAYER           0x12013
  32.  
  33. //-----------------------------------------------------------------------------
  34. // Player Health Message Structure
  35. //-----------------------------------------------------------------------------
  36. struct PlayerHealthMsg : public NetworkMessage
  37. {
  38.     float health; // Absolute health of the player.
  39. };
  40.  
  41. //-----------------------------------------------------------------------------
  42. // Player Move Message Structure
  43. //-----------------------------------------------------------------------------
  44. struct PlayerMoveUpdateMsg : public NetworkMessage
  45. {
  46.     D3DXVECTOR3 translation; // Player's translation.
  47.     float drive; // Player's drive direction.
  48.     float strafe; // Player's strafe direction.
  49.     bool fire; // Indicate's if the player is firing their weapon.
  50. };
  51.  
  52. //-----------------------------------------------------------------------------
  53. // Player Look Update Message Structure
  54. //-----------------------------------------------------------------------------
  55. struct PlayerLookUpdateMsg : public NetworkMessage
  56. {
  57.     float viewTilt; // Player's view tilt (i.e. rotation around the x axis).
  58.     float rotationY; // Player's rotation around the y axis.
  59. };
  60.  
  61. //-----------------------------------------------------------------------------
  62. // Player Score Message Structure
  63. //-----------------------------------------------------------------------------
  64. struct PlayerScoreMsg : public NetworkMessage
  65. {
  66.     unsigned long frags; // Player's frag count.
  67.     unsigned long deaths; // Player's death tally.
  68. };
  69.  
  70. //-----------------------------------------------------------------------------
  71. // Player Weapon Change Message Structure
  72. //-----------------------------------------------------------------------------
  73. struct PlayerWeaponChangeMsg : public NetworkMessage
  74. {
  75.     char weapon; // Weapon that the player has changed to.
  76. };
  77.  
  78. //-----------------------------------------------------------------------------
  79. // Spawn Point Message Structure
  80. //-----------------------------------------------------------------------------
  81. struct SpawnPointMsg : public NetworkMessage
  82. {
  83.     long spawnPoint; // ID of the spawn point to use.
  84. };
  85.  
  86. //-----------------------------------------------------------------------------
  87. // Spawn Point Message Structure
  88. //-----------------------------------------------------------------------------
  89. struct SpawnPlayerMsg : public NetworkMessage
  90. {
  91.     D3DXVECTOR3 translation; // Translation to spawn the player at.
  92. };
  93.  
  94. //-----------------------------------------------------------------------------
  95. // Game Class
  96. //-----------------------------------------------------------------------------
  97. class Game : public State
  98. {
  99. public:
  100.     Game();
  101.  
  102.     virtual void Load();
  103.     virtual void Close();
  104.  
  105.     virtual void RequestViewer( ViewerSetup *viewer );
  106.     virtual void Update( float elapsed );
  107.     virtual void Render();
  108.  
  109.     BulletManager *GetBulletManager();
  110.  
  111.     void HandleNetworkMessage( ReceivedMessage *msg );
  112.  
  113. private:
  114.     Material *m_crosshair; // Material used to render the crosshair.
  115.  
  116.     char m_scoreBoardNames[MAX_PATH]; // Text for displaying the names of all the connected players.
  117.     char m_scoreBoardFrags[MAX_PATH]; // Text for displaying each player's frag count.
  118.     char m_scoreBoardDeaths[MAX_PATH]; // Text for displaying each player's death tally.
  119.     Font *m_scoreBoardFont; // Font used to render the score board.
  120.  
  121.     BulletManager *m_bulletManager; // Bullet manager.
  122.     PlayerManager *m_playerManager; // Player manager.
  123.  
  124.     Sound *m_music; // The in-game music sound.
  125. };
  126.  
  127. //-----------------------------------------------------------------------------
  128. // Externals
  129. //-----------------------------------------------------------------------------
  130. extern Game *g_game;
  131.  
  132. #endif